/**
 * 
 */
package com.xbang.attendance.entity.stock;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.xbang.attendance.entity.product.Product;
import com.xbang.attendance.entity.system.EntityWarning;
import com.xbang.attendance.entity.system.Warehouse;
import com.xbang.attendance.entity.system.WarehouseProductAgreement;

import enumeration.WarningEqualesType;
import enumeration.WarningType;

/**
 * @author dev.zhang
 * 
 */
@Entity
public class InventoryWarningRecord implements Serializable {

	private static final long serialVersionUID = -6201239424457920137L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;

	@ManyToOne(cascade = { CascadeType.MERGE }, targetEntity = Warehouse.class, fetch = FetchType.EAGER)
	@JoinColumn(columnDefinition = "warehouse", referencedColumnName = "id")
	private Warehouse warehouse;

	@ManyToOne(cascade = { CascadeType.MERGE }, targetEntity = Product.class, fetch = FetchType.EAGER)
	@JoinColumn(columnDefinition = "product", referencedColumnName = "id")
	private Product product;

	@ManyToOne(cascade = { CascadeType.MERGE }, targetEntity = EntityWarning.class, fetch = FetchType.EAGER)
	@JoinColumn(columnDefinition = "entityWarning", referencedColumnName = "id")
	private EntityWarning entityWarning;

	@Enumerated(EnumType.STRING)
	private WarningEqualesType warningEqualesType;

	@ManyToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.EAGER, targetEntity = Inventory.class)
	@JoinColumn(columnDefinition = "inventory", referencedColumnName = "id")
	private Inventory inventory;

	@Enumerated(EnumType.STRING)
	private WarningType warningType;

	private BigDecimal currentNumber;

	private Date warnDate;

	private String description;

	@Column(name = "send_email")
	@org.hibernate.annotations.Type(type = "yes_no")
	private boolean sendEmail;

	/** 是否已读 */
	@Column(name = "read_warning")
	@org.hibernate.annotations.Type(type = "yes_no")
	private boolean raedWarning = false;

	/**
	 * @param entityWarning
	 * @param warehouse
	 * @param product
	 * @param inventory
	 */
	public InventoryWarningRecord initInventoryWarningRecord(EntityWarning entityWarning, Warehouse warehouse, Product product, Inventory inventory) {
		this.setCurrentNumber(inventory.getAmount());
		this.setEntityWarning(entityWarning);
		this.setProduct(product);
		this.setWarehouse(warehouse);
		this.setWarnDate(new Date());
		this.setWarningEqualesType(entityWarning.getWarningEqualesType());
		this.setWarningType(entityWarning.getWarningType());
		this.setDescription("配置数量:" + entityWarning.getOperationDislplay() + entityWarning.getNumber() + "现有库存数量:" + inventory.getAmount());
		return this;
	}

	/**
	 * @param entityWarning
	 * @param warehouse
	 * @param product
	 * @param inventory
	 */
	public InventoryWarningRecord initInventoryWarningRecord(WarehouseProductAgreement warehouseProductAgreement, Inventory inventory) {
		this.setCurrentNumber(inventory.getAmount());
		this.setProduct(warehouseProductAgreement.getProduct());
		this.setWarehouse(warehouseProductAgreement.getWarehouse());
		this.setWarnDate(new Date());
		this.setWarningEqualesType(WarningEqualesType.LQ);
		this.setWarningType(WarningType.percentage);
		this.setDescription("库存现有数量:" + inventory.getAmount() + entityWarning.getOperationDislplay() + "仓储约定数量:" + warehouseProductAgreement.getNumber()
				+ " 的百分比 : 50%");
		return this;
	}

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the warehouse
	 */
	public Warehouse getWarehouse() {
		return warehouse;
	}

	/**
	 * @param warehouse
	 *            the warehouse to set
	 */
	public void setWarehouse(Warehouse warehouse) {
		this.warehouse = warehouse;
	}

	/**
	 * @return the product
	 */
	public Product getProduct() {
		return product;
	}

	/**
	 * @param product
	 *            the product to set
	 */
	public void setProduct(Product product) {
		this.product = product;
	}

	/**
	 * @return the entityWarning
	 */
	public EntityWarning getEntityWarning() {
		return entityWarning;
	}

	/**
	 * @param entityWarning
	 *            the entityWarning to set
	 */
	public void setEntityWarning(EntityWarning entityWarning) {
		this.entityWarning = entityWarning;
	}

	/**
	 * @return the warningEqualesType
	 */
	public WarningEqualesType getWarningEqualesType() {
		return warningEqualesType;
	}

	/**
	 * @param warningEqualesType
	 *            the warningEqualesType to set
	 */
	public void setWarningEqualesType(WarningEqualesType warningEqualesType) {
		this.warningEqualesType = warningEqualesType;
	}

	/**
	 * @return the warningType
	 */
	public WarningType getWarningType() {
		return warningType;
	}

	/**
	 * @param warningType
	 *            the warningType to set
	 */
	public void setWarningType(WarningType warningType) {
		this.warningType = warningType;
	}

	/**
	 * @return the currentNumber
	 */
	public BigDecimal getCurrentNumber() {
		return currentNumber;
	}

	/**
	 * @param currentNumber
	 *            the currentNumber to set
	 */
	public void setCurrentNumber(BigDecimal currentNumber) {
		this.currentNumber = currentNumber;
	}

	/**
	 * @return the warnDate
	 */
	public Date getWarnDate() {
		return warnDate;
	}

	/**
	 * @param warnDate
	 *            the warnDate to set
	 */
	public void setWarnDate(Date warnDate) {
		this.warnDate = warnDate;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the inventory
	 */
	public Inventory getInventory() {
		return inventory;
	}

	/**
	 * @param inventory
	 *            the inventory to set
	 */
	public void setInventory(Inventory inventory) {
		this.inventory = inventory;
	}

	/**
	 * @return the raedWarning
	 */
	public boolean isRaedWarning() {
		return raedWarning;
	}

	/**
	 * @param raedWarning
	 *            the raedWarning to set
	 */
	public void setRaedWarning(boolean raedWarning) {
		this.raedWarning = raedWarning;
	}

	/**
	 * @return the sendEmail
	 */
	public boolean isSendEmail() {
		return sendEmail;
	}

	/**
	 * @param sendEmail
	 *            the sendEmail to set
	 */
	public void setSendEmail(boolean sendEmail) {
		this.sendEmail = sendEmail;
	}

}
